package xyz.yuzegod.megawalls.classes.normal.cow;

import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import xyz.yuzegod.megawalls.MegaWalls;
import xyz.yuzegod.megawalls.classes.Classes;
import xyz.yuzegod.megawalls.classes.CollectSkill;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.stats.KitStatsContainer;
import xyz.yuzegod.megawalls.util.ItemUtils;
import xyz.yuzegod.megawalls.util.PlayerUtils;
import xyz.yuzegod.megawalls.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class FourthSkill extends CollectSkill
{
    public FourthSkill(final Classes classes) {
        super("超级巴氏杀菌", classes);
    }
    
    @Override
    public int maxedLevel() {
        return 3;
    }
    
    @Override
    public double getAttribute(final int level) {
        switch (level) {
            case 1: {
                return 0.01;
            }
            case 2: {
                return 0.02;
            }
            case 3: {
                return 0.03;
            }
            default: {
                return 0.01;
            }
        }
    }
    
    @Override
    public List<String> getInfo(final int level) {
        final List<String> lore = new ArrayList<String>();
        if (level == 1) {
            lore.add(" §8▪ §7石头有§a" + StringUtils.percent(this.getAttribute(level)) + "§7掉落牛奶桶。");
            lore.add("   §7饮用牛奶桶可获得抗性提升I和生命恢复I,");
            lore.add("   §7持续5秒。牛奶桶可被丢出。");
            lore.add("   §7对于非奶牛职业的玩家,生命恢复加倍。");
            return lore;
        }
        lore.add(" §8▪ §7石头有§8" + StringUtils.percent(this.getAttribute(level - 1)) + " ➜ §a" + StringUtils.percent(this.getAttribute(level)) + "§7掉落牛奶桶。");
        lore.add("   §7饮用牛奶桶可获得抗性提升I和生命恢复I,");
        lore.add("   §7持续5秒。牛奶桶可被丢出。");
        lore.add("   §7对于非奶牛职业的玩家,生命恢复加倍。");
        return lore;
    }
    
    @Override
    public void upgrade(final GamePlayer gamePlayer) {
        final KitStatsContainer kitStats = gamePlayer.getPlayerStats().getKitStats(this.getClasses());
        kitStats.addSkill4Level();
    }
    
    @Override
    public int getPlayerLevel(final GamePlayer gamePlayer) {
        return gamePlayer.getPlayerStats().getKitStats(this.getClasses()).getSkill4Level();
    }
    
    @Override
    public void onBlockBreak(final KitStatsContainer kitStats, final BlockBreakEvent e) {
        if (ItemUtils.matchMaterial(e.getBlock(),Material.STONE) && MegaWalls.getRandom().nextInt(100) <= this.getAttribute(kitStats.getSkill4Level()) * 100.0) {
            e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.COW_IDLE, 1.0f, 1.0f);
           PlayerUtils.gatheringItem(new ItemStack(Material.MILK_BUCKET,2),e);
        }
    }
}
